#!/usr/bin/python
#coding:utf8

"""
Composite
"""

from abc import ABC, abstractmethod
# 虚类文件类，是所有文件或文件夹的父类，提供统一接口
class File(ABC):
    @abstractmethod
    def add(self,file):
        pass
    @abstractmethod
    def show(self,depth=0):
        pass
    
class ImageFile(File):
    def __init__(self,file_name):
        self.file_name = file_name
    def add(self,file):
        print("ImageFile can't add file")
    def show(self,depth=0):
        temp_str = "-"*depth + self.file_name
        print(temp_str)
        
class TextFile(File):
    def __init__(self,file_name):
        self.file_name = file_name
    def add(self,file):
        print("TextFile can't add file")
    def show(self,depth=0):
        temp_str = "-"*depth + self.file_name
        print(temp_str)

# 定义Composite类
class Folder(File):
    def __init__(self,file_name):
        self.file_name = file_name
        self.subfiles = []
    def add(self,file):
        self.subfiles.append(file)
    def show(self,depth=0):
        temp_str = "-"*depth + self.file_name
        print(temp_str)
        for subfile in self.subfiles:
            subfile.show(depth+2)

if __name__ == "__main__":
    folder1 = Folder("folder1")
    folder1.add(ImageFile("image1.jpg"))
    folder1.add(ImageFile("image2.jpg"))
    folder2 = Folder("folder2")
    folder1.add(folder2)
    folder2.add(TextFile("text1.txt"))
    folder2.add(TextFile("text2.txt"))
    folder1.show()
    print('------'*10)
    folder2.show()
